package com.tanhua.server.controller;

import com.tanhua.server.service.ManagerService;
import com.tanhua.server.vo.RecommendUserQueryParam;

import com.tanhua.server.vo.UserInfoPageResult;
import com.tanhua.server.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/management/manage")
public class UserInfoController {
    @Autowired
    private ManagerService managerService;
    /**
     * 查询所有用户信息

     * @return
     */
    @GetMapping("/users")
    public ResponseEntity<UserInfoPageResult>queryFindUserInfo( RecommendUserQueryParam queryParam){
        try {
            UserInfoPageResult pageResult= managerService.queryFindUserInfo(queryParam);
            if (pageResult!=null){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 查询个人信息
     * @param userId
     * @return
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity<UserInfoVo>queryUserById(@PathVariable("userId")Integer userId){
        try {
            UserInfoVo user=managerService.queryUserById(userId);
            return ResponseEntity.ok(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


}
